package com.du.design.test;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * Desc:
 * Author: dushuang
 * Date: 2023/3/4
 **/
public class Simple {

    int x = 0;
    boolean flag = false;
    public void writer() {
        x = 42; //1
        flag = true; //2
    }
    public void reader() {
        if (flag) { //3
            System.out.println(x); //4
        }
    }

    /**
     * 实现 java.lang.Runnable 接口
     */
    public class MyRunnable implements Runnable {
        public void run() {
            // 线程执行的代码
        }
    }

    /**
     * 继承 java.lang.Thread
     */
    public class MyThread extends Thread {
        public void run() {
            // 线程执行的代码
        }
    }

    public static void main(String[] args) throws Exception{
        // 使用Lambda表达式创建线程
        Thread thread = new Thread(() -> {
            // 线程执行的代码
        });
        thread.start();

        thread.sleep(1000L);

        // 获取线程状态
        System.out.println(thread.getState());
    }



}
